# Building on windows is really slow, so this workflow is separate from e2e.yml and only builds on changes
# to the cli itself. They're more likely to introduce issues on windows, compared to changes to core and yarn.lock.

name: E2E Windows
on:
  # NOTE: If you change these you must update verify_e2e-windows-noop.yml as well
  pull_request:
    paths:
      - 'yarn.lock'
      - '.github/workflows/verify_e2e-windows.yml'
      - 'packages/cli/**'
      - 'packages/e2e-test/**'
      - 'packages/create-app/**'

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  build:
    runs-on: windows-2022

    strategy:
      matrix:
        node-version: [18.x, 20.x]

    env:
      CI: true
      NODE_OPTIONS: ${{ matrix.node-version == '20.x' && '--max-old-space-size=8192 --no-node-snapshot' || '--max-old-space-size=8192' }}

    name: E2E Windows ${{ matrix.node-version }}
    steps:
      - name: Harden Runner
        uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0
        with:
          egress-policy: audit

      # In order to have the create-app template function as if it was downloaded from NPM
      # we need to make sure we checkout files with LF line endings only
      - name: Set git to use LF
        run: |
          git config --global core.autocrlf false
          git config --global core.eol lf

      - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

      - name: Configure Git
        run: |
          git config --global user.email noreply@backstage.io
          git config --global user.name 'GitHub e2e user'

      - name: use node.js ${{ matrix.node-version }}
        uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
        with:
          node-version: ${{ matrix.node-version }}
          registry-url: https://registry.npmjs.org/ # Needed for auth

      - name: setup python
        uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0
        with:
          python-version: '3.10'

      - name: Add msbuild to PATH
        uses: microsoft/setup-msbuild@6fb02220983dee41ce7ae257b6f4d8f9bf5ed4ce # v2.0.0

      - name: Setup gyp env
        run: |
          echo 'GYP_MSVS_VERSION=2022' >> $Env:GITHUB_ENV
          echo 'GYP_MSVS_OVERRIDE_PATH=C:\\Dummy' >> $Env:GITHUB_ENV

      - name: Install latest gyp and set node-gyp path
        shell: powershell
        run: |
          npm prefix -g | % {npm config set dev_dir "c:\temp\.gyp2"}
          npm prefix -g | % {npm config set node_gyp "$_\node_modules\node-gyp\bin\node-gyp.js"}

      - name: setup chrome
        uses: browser-actions/setup-chrome@803ef6dfb4fdf22089c9563225d95e4a515820a0 # latest

      - name: yarn install
        uses: backstage/actions/yarn-install@a674369920067381b450d398b27df7039b7ef635 # v0.6.5
        with:
          cache-prefix: ${{ runner.os }}-v${{ matrix.node-version }}

      - run: yarn tsc
      - run: yarn backstage-cli repo build
      - name: run E2E test
        run: yarn e2e-test run
        env:
          DEBUG: zombie
          CYPRESS_VERIFY_TIMEOUT: 600000
